package com.by.controller;

import com.by.bean.ErpPurchaseOrder;
import com.by.bean.ResultBean;
import com.by.group.V;
import com.by.mapper.ErpPurchaseOrderMapper;
import com.by.service.ErpPurchaseOrderService;
import com.by.utils.Assert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :LYJ
 * @version : 1.0
 * @date : 2025/3/5 15:40
 * @desc :
 * @since : JDK17
 */
@RestController
@Api(tags = "采购订单主表")
@RequestMapping("/api")
public class ErpPurchaseOrderController extends BaseController {
    @Autowired
    ErpPurchaseOrderMapper erpPurchaseOrderMapper;
    @Autowired
    ErpPurchaseOrderService erpPurchaseOrderService;

    @PostMapping("/supplier/purseList")
    @ApiOperation("查看采购订单表所有信息")
    public ResultBean queryAll(@RequestBody @Validated ErpPurchaseOrder erpPurchaseOrder, BindingResult result) {
        V.validate(result);
        return success("success", erpPurchaseOrderService.queryAll(erpPurchaseOrder));
    }

    @PostMapping("/supplier/purseSave")
    @ApiOperation("添加采购订单表信息")
    public ResultBean save(@RequestBody @Validated ErpPurchaseOrder erpPurchaseOrder, BindingResult result) {
        V.validate(result);
        int res = erpPurchaseOrderMapper.save(erpPurchaseOrder);
        Assert.isZero(res, "添加信息失败");
        return success("success", erpPurchaseOrder);
    }
}
